package com.kyxx.topics.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.kyxx.topics.R;
import com.kyxx.topics.view.MyCommonTitle;

/**
 * Created by Administrator on 2016/9/29.
 */
public class UserAddNewAddress extends Activity implements View.OnClickListener {
    private MyCommonTitle myCommonTitle;
    private TextView tvTitle, btnSave, btnDelete, btnAddress;
    private EditText edReceiver, edMobile, edPostCode, edDetailsAddress;
    private ToggleButton tgDefaultAddress;
    private boolean isDefaultAddress;
    private int type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        type = getIntent().getIntExtra("type", -1);//1为新增  2为修改
        setContentView(R.layout.activity_user_add_new_address);

        initView();
        initListener();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        myCommonTitle = (MyCommonTitle) findViewById(R.id.aci_myTitle);
        if (type == 1) {
            myCommonTitle.setTitle("新增地址");
        } else if (type == 2) {
            myCommonTitle.setTitle("编辑地址");
            btnDelete.setVisibility(View.VISIBLE);
            showData();
        }
        myCommonTitle.setLisener(this, null);
        btnSave = (TextView) findViewById(R.id.aci_edit_btn);//保存
        btnSave.setText("保存");

        edReceiver = (EditText) findViewById(R.id.ed_receiver);//收货人
        edMobile = (EditText) findViewById(R.id.ed_mobile);//手机号
        edPostCode = (EditText) findViewById(R.id.ed_post_code);//邮编
        btnAddress = (TextView) findViewById(R.id.btn_address);//省市区
        edDetailsAddress = (EditText) findViewById(R.id.ed_details_address);//详细地址
        btnDelete = (TextView) findViewById(R.id.btn_delete_address);//删除地址
        tgDefaultAddress = (ToggleButton) findViewById(R.id.tg_default_address);

        tgDefaultAddress.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                isDefaultAddress = isChecked;
            }
        });
    }

    /**
     * 当type为2时,显示编辑功能,显示数据信息
     */
    private void showData() {
        edReceiver.setText("");
        edMobile.setText("");
        edPostCode.setText("");
        btnAddress.setText("");
        edDetailsAddress.setText("");
        if (type == 1) {//待修改,,  根据不同值显示不同图片
            tgDefaultAddress.setBackgroundResource(R.drawable.switch_on);
        } else {
            tgDefaultAddress.setBackgroundResource(R.drawable.switch_off);
        }
    }

    private void initListener() {
        btnSave.setOnClickListener(this);
        btnDelete.setOnClickListener(this);
        btnAddress.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aci_edit_btn://保存

                break;
            case R.id.btn_delete_address://删除

                break;
        }
    }
}
